import request from '@/utils/request';

/* SpuForm组件 */

//获取spu列表
export const reqSpu = (page, limit, category3Id) => request({
    url: `/admin/product/${page}/${limit}`,
    method: 'get',
    params: { category3Id }
})

//获取spu信息
export const reqSpuList = (spuId) => request({
    url: `/admin/product/getSpuById/${spuId}`,
    method: 'get'
})

//获取品牌的信息
export const reqTradeMarkList = () => request({
    url: '/admin/product/baseTrademark/getTrademarkList',
    method: 'get'
})

//获取SPU图片的接口-------------【SpuForm组件与SkuForm组件共用接口】
export const reqSpuImageList = (spuId) => request({
    url: `/admin/product/spuImageList/${spuId}`,
    method: 'get'
})

//获取销售属性
export const reqBaseSaleAttrList = () => request({
    url: '/admin/product/baseSaleAttrList',
    method: 'get'
})

//保存或修改请求  取决于有无id
export const reqAddOrUpdateList = (spuList) => {
    if (spuList.id) {
        return request({
            url: '/admin/product/updateSpuInfo',
            method: 'post',
            data: spuList
        })
    } else {
        return request({
            url: '/admin/product/saveSpuInfo',
            method: 'post',
            data: spuList
        })
    }
}

//点击删除按钮 请求
export const reqDeleteData = (spuId) => request({
    url: `/admin/product/deleteSpu/${spuId}`,
    method: 'delete'
})




/* --------------------------------- */




/* SkuForm组件 */

//获取销售属性的数据
export const reqSpuSaleAttrList = (spuId) => request({
    url: `/admin/product/spuSaleAttrList/${spuId}`,
    method: 'get'
})

//获取平台属性的数据
export const reqAttrInfoList = (category1Id, category2Id, category3Id) => request({
    url: `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`,
    method: 'get'
})

//添加SKU
export const reqAddSku = (skuInfo) => request({
    url: '/admin/product/saveSkuInfo',
    method: 'post',
    data: skuInfo
})

//获取SKU列表数据的接口
export const reqSkuList = (spuId) => request({
    url: `/admin/product/findBySpuId/${spuId}`,
    method: 'get'
})